<?php

namespace App\Entity;

use App\Repository\PageRepository;
use App\Utils\Helper\GetterHelper;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=PageRepository::class)
 * @ORM\HasLifecycleCallbacks()
 */
class Page {
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, options={"comment"="标题"})
     */
    private $title;

    /**
     * @ORM\Column(type="string", length=500, nullable=true, options={"comment"="摘要"})
     */
    private $summary;

    /**
     * @ORM\Column(type="text", nullable=true, options={"comment"="正文内容"})
     */
    private $content;

    /**
     * @ORM\Column(type="string", length=255, nullable=true, options={"comment"="缩率图"})
     */
    private $thumbnail;

    /**
     * @ORM\Column(type="boolean", nullable=true, options={"default"=0, "comment"="是否开启评论，0关闭，1开启"})
     */
    private $is_comment;

    /**
     * @ORM\Column(type="integer", options={"comment"="类别ID"})
     */
    private $page_category_id;

    /**
     * @ORM\Column(type="json", nullable=true, options={"comment"="标签"})
     */
    private $page_tags = [];

    /**
     * @ORM\Column(type="integer", length=255, nullable=true, options={"default"="1", "comment"="状态：-1删除，0待发布，1已发布"})
     */
    private $status = 1;

    /**
     * @ORM\Column(type="string", length=255, nullable=true, options={"default"="now", "comment"="发布模式：now及时发布，timing定时发布"})
     */
    private $publish_type = "now";

    /**
     * @ORM\Column(type="integer", nullable=true, options={"comment"="创建人ID"})
     */
    private $admin_user_id;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $created_at;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $updated_at;

    /**
     * @ORM\Column(type="datetime", nullable=true, options={"comment"="发布时间"})
     */
    private $publish_time;

    /**
     * @ORM\Column(type="integer", nullable=true, options={"default"="0", "comment"="阅读量"})
     */
    private $page_view = 0;

    /**
     * @ORM\Column(type="integer", nullable=true, options={"default"="0", "comment"="点赞量"})
     */
    private $page_like = 0;

    /**
     * @ORM\Column(type="boolean", length=255, nullable=true, options={"default"="0", "comment"="置顶：0否，1是"})
     */
    private $is_top = 0;

    /**
     * @ORM\Column(type="boolean", length=255, nullable=true, options={"default"="0", "comment"="推荐：0否，1是"})
     */
    private $is_recommend = 0;

    /**
     * @ORM\Column(type="boolean", length=255, nullable=true, options={"default"="1", "comment"="发布状态：0待发布，1已发布"})
     */
    private $publish_status = 1;

    /**
     * @ORM\Column(type="string", length=255, nullable=true, options={"comment"="seo 关键词"})
     */
    private $seo_key;

    /**
     * @ORM\Column(type="string", length=255, nullable=true, options={"comment"="seo 描述"})
     */
    private $seo_description;

    public $page_publish;

    public $thumbnail_item;

    public $author;

    public function getId (): ?int {
        return $this->id;
    }

    public function getTitle (): ?string {
        return $this->title;
    }

    public function setTitle (?string $title): self {
        $this->title = $title;

        return $this;
    }

    public function getSummary (): ?string {
        return $this->summary;
    }

    public function setSummary (?string $summary): self {
        $this->summary = $summary;

        return $this;
    }

    public function getContent (): ?string {
        return $this->content;
    }

    public function setContent (?string $content): self {
        $this->content = $content;

        return $this;
    }

    public function getThumbnail (): ?string {
        return $this->thumbnail;
    }

    public function setThumbnail (?string $thumbnail): self {
        $this->thumbnail = $thumbnail;

        return $this;
    }

    public function getIsComment (): ?bool {
        return $this->is_comment;
    }

    public function setIsComment (bool $is_comment): self {
        $this->is_comment = $is_comment;

        return $this;
    }

    public function getPageCategoryId (): ?int {
        return $this->page_category_id;
    }

    public function setPageCategoryId (int $page_category_id): self {
        $this->page_category_id = $page_category_id;

        return $this;
    }

    public function getPageTags (): ?array {
        return $this->page_tags;
    }

    public function setPageTags (?array $page_tags): self {
        $this->page_tags = $page_tags;

        return $this;
    }

    public function getAdminUserId (): ?int {
        return $this->admin_user_id;
    }

    public function setAdminUserId (?int $admin_user_id): self {
        $this->admin_user_id = $admin_user_id;

        return $this;
    }

    public function getCreatedAt (): ?\DateTimeInterface {
        return $this->created_at;
    }

    public function setCreatedAt (?\DateTimeInterface $created_at): self {
        $this->created_at = $created_at;

        return $this;
    }

    public function getUpdatedAt (): ?\DateTimeInterface {
        return $this->updated_at;
    }

    public function setUpdatedAt (?\DateTimeInterface $updated_at): self {
        $this->updated_at = $updated_at;

        return $this;
    }

    public function getPublishTime (): ?\DateTimeInterface {
        return $this->publish_time;
    }

    public function setPublishTime (?\DateTimeInterface $publish_time): self {
        $this->publish_time = $publish_time;

        return $this;
    }

    public function getPageView (): ?int {
        return $this->page_view;
    }

    public function setPageView (?int $page_view): self {
        $this->page_view = $page_view;

        return $this;
    }

    public function getPublishType (): ?string {
        return $this->publish_type;
    }

    public function setPublishType (?string $publish_type): self {
        $this->publish_type = $publish_type;

        return $this;
    }

    public function getStatus (): ?int {
        return $this->status;
    }

    public function setStatus (?int $status): self {
        $this->status = $status;

        return $this;
    }

    public function getPublishStatus (): ?bool {
        return $this->publish_status;
    }

    public function setPublishStatus (?bool $publish_status): self {
        $this->publish_status = $publish_status;

        return $this;
    }

    public function getPageComment () {
        return GetterHelper::getEntityManager()->getRepository(PageComment::class)->getCountByPageId($this->getId());
    }

    public function getPageCategory () {
        return GetterHelper::getEntityManager()->getRepository(PageCategory::class)->find($this->getPageCategoryId());
    }

    /**
     * 新建之后 hook
     * @ORM\PostPersist()
     */
    public function PostPersistHook () {

    }

    /**
     * 更新之后 hook
     * @ORM\PostUpdate()
     */
    public function PostUpdateHook () {

    }

    /**
     * 删除之后 hook
     * @ORM\PostRemove()
     */
    public function PostRemoveHook () {

    }

    public function getIsTop (): ?bool {
        return $this->is_top;
    }

    public function setIsTop (?bool $is_top): self {
        $this->is_top = $is_top;

        return $this;
    }

    public function getPageLike (): ?int {
        return $this->page_like;
    }

    public function setPageLike (?int $page_like): self {
        $this->page_like = $page_like;

        return $this;
    }

    public function getIsRecommend (): ?bool {
        return $this->is_recommend;
    }

    public function setIsRecommend (?bool $is_recommend): self {
        $this->is_recommend = $is_recommend;

        return $this;
    }

    public function getSeoKey (): ?string {
        return $this->seo_key;
    }

    public function setSeoKey (?string $seo_key): self {
        $this->seo_key = $seo_key;

        return $this;
    }

    public function getSeoDescription (): ?string {
        return $this->seo_description;
    }

    public function setSeoDescription (?string $seo_description): self {
        $this->seo_description = $seo_description;

        return $this;
    }

    public function getTags () {
        return GetterHelper::getEntityManager()->getRepository(PageTag::class)->getTags($this->getPageTags());
    }

    public function getAvatar () {
        return GetterHelper::getEntityManager()->getRepository(AdminUser::class)->getAvatar($this->getAdminUserId());
    }

    public function getAuthor () {
        return GetterHelper::getEntityManager()->getRepository(AdminUser::class)->getAuthor($this->getAdminUserId());
    }
}
